package com.ruiysoft.service.order.facade.util;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruiysoft.entity.order.OrderMain;

import java.util.List;
import java.util.Optional;

/**
 * Date : 2018/11/27
 *
 * @author WenJialu
 */
public enum OrderEntityWrapperUtil {

    INSTANCE;

    public QueryWrapper<OrderMain> createOrderMainWrapper(String orderNo, Long userId, Long shopId, Integer orderDbStatus, List<Integer> orderDbStatusIn) {
        QueryWrapper<OrderMain> wrapper = new QueryWrapper<>();
        Optional.ofNullable(orderNo).ifPresent(x -> wrapper.eq("order_no", x));
        Optional.ofNullable(userId).ifPresent(x -> wrapper.eq("user_id", x));
        Optional.ofNullable(shopId).ifPresent(x -> wrapper.eq("shop_id", x));
        Optional.ofNullable(orderDbStatus).ifPresent(x -> wrapper.eq("status", x));
        Optional.ofNullable(orderDbStatusIn).ifPresent(x -> wrapper.in("status", x));
        Optional.ofNullable(orderNo).ifPresent(x -> wrapper.eq("order_no", x));
        wrapper.eq("del_flag", false)
                .orderBy(true, false, "create_time");
        return wrapper;
    }

}
